package com.google.location.im.ui;

import java.util.Hashtable;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Displayable;

import de.enough.polish.ui.Form;
import de.enough.polish.ui.TextField;
import de.enough.polish.util.Locale;

/**
 * @author tharindu
 */
public class LoginScreen extends Form implements
	javax.microedition.lcdui.CommandListener {
    private MainUI ui_;

    private Hashtable commands_;

    private boolean valid;

    //#style textfieldItem
    final private TextField username_ = new TextField(Locale.get("locateim.login.username"), "tharindu", 10, TextField.ANY);// [LOCALE]

    //#style textfieldItem
    final private TextField password_ = new TextField(Locale.get("locateim.login.password"), "tharindu", 10, TextField.ANY|TextField.PASSWORD);// [LOCALE]

    public LoginScreen() {

	//#style ftScreen
	super(Locale.get("locateim.login.title")); // [LOCALE]

	ui_ = MainUI.getInstance();
	commands_ = ui_.getCommands();

	try {
	    setCommandListener(this);
	} catch (Exception e) {
	    e.printStackTrace();
	}
	addCommand((Command) commands_.get(new Integer(MainUI.CMD_OK)));
	addCommand((Command) commands_.get(new Integer(MainUI.CMD_EXIT)));

	this.append(username_);
	this.append(password_);

    }

    public boolean isValidInput() {
	valid = false;
	if (username_.getText().length() != 0
		&& password_.getText().length() != 0) {
	    valid = true;
	}
	return valid;
    }

    public void commandAction(Command c, Displayable d) {
	MainUI.hsenidCommand(c, d);
    }

}
